package com.example.demo.study;

public class Test3 {
    public static void main(String[] args) {


        int i = countPrimes(1500000);
        System.out.println(i);
    }

    public static int titleToNumber(String columnTitle) {
        int[] num = new int[]{1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26};
        int res = 0;
        for (int i = columnTitle.length() - 1, j = 0; i >= 0; i--, j++) {
            char c = columnTitle.charAt(j);
            res += num[c - 'A'] * Math.pow(26, i);
        }
        return res;
    }


    public static int countPrimes(int n) {
        if (n <= 1) {
            return 0;
        }
        int num = 0;
        for (int i = 2; i < n; i++) {
            if (isPrime(i)) {
                num++;
            }
        }
        return num;
    }

    public static boolean isPrime(int num) {
        for (int i = 2; i <= (int) Math.sqrt(num); i++) {
            if (num % i == 0) {
                return false;
            }
        }
        return true;
    }
}
